import { Body, Controller, Get, Post, Query, Req } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AppGatherService } from './gather.service';
import { Gather } from './gather.entity';
import { ApiRes, ApiResType } from 'src/common/decorator/api-res.decorator';
import { AppGatherDtoParams } from './dto/list.dto';
import { Public } from 'src/common/decorator/public.decorator';
import { AppGatherQueryDto } from './dto/query.dto';

@ApiTags('app合辑模块')
@Controller('app/gather')
export class AppGatherController {
  constructor(private readonly appCollectionService: AppGatherService) {}

  @ApiOperation({
    summary: '根据分类id查询合辑列表',
  })
  @Post('/list')
  @Public()
  @ApiRes(Gather, ApiResType.ARRAY)
  async list(@Body() data: AppGatherDtoParams) {
    return {
      data: await this.appCollectionService.findAll(data),
    };
  }

  @ApiOperation({
    summary: '查询已收藏的合辑',
  })
  @Post('/collectionList')
  @ApiBearerAuth()
  @ApiRes(Gather, ApiResType.ARRAY)
  async collectionList(@Req() req) {
    const data = req.auth;
    return {
      data: await this.appCollectionService.findCollectionList(data.uid),
    };
  }

  @ApiOperation({
    summary: '根据id查询合辑详情',
  })
  @Get('/query')
  @ApiBearerAuth()
  @ApiRes(Gather, ApiResType.ARRAY)
  async query(@Req() req, @Query() query: AppGatherQueryDto) {
    const data = req.auth;
    return {
      data: await this.appCollectionService.findGatherByIdAndCheckFollow(
        query.id,
        data.uid,
      ),
    };
  }

  @Get('/update-article-count')
  @Public()
  async updateArticleCount(@Query() query: AppGatherQueryDto) {
    return {
      data: await this.appCollectionService.updateArticleTotal(query.id),
    };
  }

  // @Get('test')
  // async chatTest() {
  //   const chat = {
  //     id: 3,
  //     content: [
  //       {
  //         type: 'text',
  //         text: '你好, 告诉我唐诗三百首有那几首',
  //         image_url: '',
  //       },
  //     ],
  //   };
  //   return this.gptService.streamPost(
  //     'https://api.aiskt.com/v1/chat/completions',
  //     {
  //       model: 'gpt-3',
  //       stream: true,
  //       messages: [
  //         {
  //           role: 'user',
  //           content: chat.content,
  //         },
  //       ],
  //     },
  //   );
  // }
}
